package kr.hkit.androidcomplete02.ch12;

import kr.hyunist.androidcomplete01.*;
import android.app.*;
import android.os.*;
import android.view.*;
import android.widget.*;
import android.widget.AdapterView.OnItemSelectedListener;

public class SpinnerEx extends Activity {
	ArrayAdapter<CharSequence> adapter;
	private boolean mInitSpinner;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch12_spinner);
		
		Spinner spin = (Spinner) findViewById(R.id.ch12_myspinner);
		spin.setPrompt("골라골라~!");
		
		adapter = ArrayAdapter.createFromResource(this, R.array.fruits, android.R.layout.simple_spinner_item);
		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		
		spin.setAdapter(adapter);
		
		spin.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> parent, View view,
					int position, long id) {
				if(mInitSpinner == false){
					mInitSpinner = true;
					return;
				}
				Toast.makeText(getApplicationContext(), adapter.getItem(position) + " 맛있다.", Toast.LENGTH_SHORT).show();	
			}

			@Override
			public void onNothingSelected(AdapterView<?> parent) {}
		});

				
	}
}
